# Maintainer: Francesco Colista <fcolista@alpinelinux.org>
pkgname=gtest
pkgver=1.15.2
pkgrel=0
pkgdesc="Google Test - C++ testing utility based on the xUnit framework (like JUnit)"
url="https://github.com/google/googletest"
arch="all"
license="BSD-3-Clause"
depends_dev="$pkgname=$pkgver-r$pkgrel gmock=$pkgver-r$pkgrel"
makedepends="$depends_dev cmake python3-dev samurai"
subpackages="$pkgname-dev gmock $pkgname-src::noarch"
source="$pkgname-$pkgver.tar.gz::https://github.com/google/googletest/archive/refs/tags/v$pkgver.tar.gz"
builddir="$srcdir/googletest-$pkgver"

build() {
	cmake -B build -G Ninja \
		-DCMAKE_BUILD_TYPE=MinSizeRel \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_INSTALL_LIBDIR=lib \
		-DBUILD_SHARED_LIBS=ON \
		-Dgtest_build_tests=ON \
		-DBUILD_GMOCK=ON
	cmake --build build
}

check() {
	# fails of x86
	ctest --test-dir build -E "(googletest-port-test|googletest-printers-test)"
}

package() {
	DESTDIR="$pkgdir" cmake --build build --target install
	find "$pkgdir" -name '*.pump' -print -delete
}

gmock() {
	pkgdesc="Google Mock - A library for writing and using C++ mock classes"
	amove usr/lib/libgmock'*.so*'
}

src() {
	mkdir -p "$subpkgdir"/usr/src/$pkgname/src
	mv  "$builddir"/googletest/src/* "$subpkgdir"/usr/src/$pkgname/src
}

sha512sums="
9046841044a2bf7edfd96854ad9c44ffae4fcb9fb59a075b367507c0762a98eb32cb6968d46663228272e26321e96f4dd287c95baa22c6af9bad902b8b6ede4e  gtest-1.15.2.tar.gz
"
